package cn.huiyunche.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.interfaces.QiniuService;
import cn.huiyunche.base.service.vo.Result;

@Controller
@RequestMapping("/qiniu")
public class QiniuController {
	
	@Autowired
	private QiniuService qiniuService = null;
	
	/**
	 * 获取简单上传授权
	 * @return  jeson data
	 */
	@RequestMapping(value="/upload/ticket",method = RequestMethod.GET)
	@ResponseBody
	public Result<String> getSimpleUploadToken(){
		return this.getQiniuService().getSimpleUploadToken();
	}
	
	/**
	 * 获取汽车LOGO上传token
	 * @return  jeson data
	 */
	@RequestMapping(value="/upload/brandlogo",method = RequestMethod.GET)
	@ResponseBody
	public Result<String> getSimpleUploadTokenForBrandLogo(){
		return this.getQiniuService().getSimpleUploadTokenForBrandLogo();
	}
	
	/**
	 * 获取下载授权
	 * @return  jeson data
	 * @throws Exception 
	 */
	@RequestMapping(value="/download/ticket",method = RequestMethod.GET)
	@ResponseBody
	public Result<String> getDownloadUrl(String key, String mode, String w, String h){
		return this.getQiniuService().getDownloadUrl(key, mode, w, h);
	}
	/**
	 * 获取下载商品车LOGO授权
	 * @return  jeson data
	 * @throws Exception 
	 */
	@RequestMapping(value="/downloadbrand/ticket",method = RequestMethod.GET)
	@ResponseBody
	public Result<String> getDownloadBrandUrl(String key){
		Result<String> result = new Result<String>(true, null, "上传成功");
		result.setData(this.getQiniuService().getDownloadBrandUrl(key));
		return result;
	}
	
	private QiniuService getQiniuService() {
		return this.qiniuService;
				
	}
}
